var hsList = [];

function initPage() {
    jQuery("img[logoid]").each(function(ndx, item) {
        if (jQuery(item).attr("logoid") && jQuery(item).attr("logoid") != "0") {
            item.src = generateServiceUrl({
                service : "getlogo",
                page : "companyprofile",
                params : {
                    fileid : jQuery(item).attr("logoid")
                }
            });
            jQuery(item).show();
        } else {
            jQuery(item).hide();
        }
    });
    callService("services", "getavailableservices", {}, {
        success : function(result) {
            for (var i = 0; i < result.items.length; i++) {
                jQuery("select[name='service_id']").append(jQuery("<option>")
                    .text(result.items[i].text)
                    .val(result.items[i].value)
                );
            }
            jQuery("select[name='service_id']").val(jQuery("select[name='service_id']").attr("selectedvalue"));
        }
    });
}

function uploadCompanyLogo() {
    openPopup("logoupload", {
        width : 450,
        height: 180,
        title : "Upload your company logo",
        extraParams : {
            popup_id : "company_logo"
        }
    });
}

function doAfterUpload(parameters) {
    if (parameters.popupId == "company_logo") {
        jQuery("input[name='logo_id']").val(popupResult.logofileid);
        jQuery("img#logo_preview")
            .attr("src", generateServiceUrl({
                service : "getlogo",
                page : "companyprofile",
                params : {
                    fileid : popupResult.logofileid
                }
            }))
            .show("fade", { }, 500)
        ;
    } else if (parameters.popupId.indexOf("export_logo") === 0) {
        var ndx = parameters.popupId.split("_")[2];
        jQuery("input[name='export_logo_id_" + ndx + "']").val(popupResult.logofileid);
        jQuery("img#export_logo_preview_" + ndx)
            .attr("src", generateServiceUrl({
                service : "getlogo",
                page : "companyprofile",
                params : {
                    fileid : popupResult.logofileid
                }
            }))
            .show("fade", { }, 500)
        ;
    } else if (parameters.popupId.indexOf("import_logo") === 0) {
        var ndx = parameters.popupId.split("_")[2];
            jQuery("input[name='import_logo_id_" + ndx + "']").val(popupResult.logofileid);
        jQuery("img#import_logo_preview_" + ndx)
            .attr("src", generateServiceUrl({
                service : "getlogo",
                page : "companyprofile",
                params : {
                    fileid : popupResult.logofileid
                }
            }))
            .show("fade", { }, 500)
        ;
    }
}
